<?php

class FieldDefinition implements IFieldDefinition
{

  /**
   *
   * @var boolean
   */
  protected $autoIncrement;

  /**
   *
   * @var mixed
   */
  protected $default;

  /**
   *
   * @var integer
   */
  protected $length;

  /**
   *
   * @var string
   */
  protected $name;

  /**
   *
   * @var boolean
   */
  protected $null;

  /**
   *
   * @var boolean
   */
  protected $primaryKey;

  /**
   *
   * @var string
   */
  protected $table;

  /**
   *
   * @var string
   */
  protected $type;

  /**
   *
   * @var boolean
   */
  protected $unsigned;

  /**
   *
   * @return void
   */
  public function __construct($type, $params = array())
  {
    $params = SimpleDictionary::parseFrom($params);

    foreach ($params->getAll() as $name => $value) {
      $this->$name = $value;
    }
  }

  public static function factory(array $params)
  {
    $type = sy_get_param($params, 0);
    $params = sy_get_param($params, 1);
    return new self($type, $params);
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/domain/api/IFieldDefinition#getTable()
   */
  public function getTable()
  {
    return $this->table;
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/domain/api/IFieldDefinition#getAutoIncrement()
   */
  public function getAutoIncrement()
  {
    return $this->autoIncrement;
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/domain/api/IFieldDefinition#getDefault()
   */
  public function getDefault()
  {
    return $this->default;
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/domain/api/IFieldDefinition#getLength()
   */
  public function getLength()
  {
    return $this->length;
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/domain/api/IFieldDefinition#getName()
   */
  public function getName()
  {
    return $this->name;
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/domain/api/IFieldDefinition#getNull()
   */
  public function getNull()
  {
    return $this->null;
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/domain/api/IFieldDefinition#getPrimaryKey()
   */
  public function getPrimaryKey()
  {
    return $this->primaryKey;
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/domain/api/IFieldDefinition#getType()
   */
  public function getType()
  {
    return $this->type;
  }

  /**
   * (non-PHPdoc)
   * @see simplify/kernel/domain/api/IFieldDefinition#getUnsigned()
   */
  public function getUnsigned()
  {
    return $this->unsigned;
  }

}

?>